package com.mes.cloud.service;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.mes.cloud.api.dto.request.menu.*;
import com.mes.cloud.api.dto.response.menu.SysMenuDto;
import com.mes.cloud.exception.BaseException;
import com.mes.cloud.common.CommPager;
import com.mes.cloud.common.JsonResult;
import com.mes.cloud.constant.Constants;
import com.mes.cloud.dao.SysMenuDao;
import com.mes.cloud.entity.SysMenu;
import com.mes.cloud.enums.HttpStatusEnum;
import com.mes.cloud.util.DateUtil;
import com.mes.cloud.util.UserUtil;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * 系统菜单
 *
 * @author wxm
 * @version 2019-07-30 13:55:22
 * @email xiaomin.wu1@pactera.com
 */
@Service
public class SysMenuService {

    private SysMenuDao sysMenuDao;

    private IPKeyGenerator iPKeyGenerator;

    private SysCodeGeneratorService sysCodeGeneratorService;

    @Autowired
    public SysMenuService(SysMenuDao sysMenuDao, IPKeyGenerator iPKeyGenerator, SysCodeGeneratorService sysCodeGeneratorService) {
        this.sysMenuDao = sysMenuDao;
        this.iPKeyGenerator = iPKeyGenerator;
        this.sysCodeGeneratorService = sysCodeGeneratorService;
    }

    /**
     * 查询右边列表
     *
     * @param menuPageListRequest
     * @return JsonResult<CommPager < SysMenuDto>>
     */
    public JsonResult<CommPager<SysMenuDto>> pageList(MenuPageListRequest menuPageListRequest) {
        Page<SysMenuDto> page = PageHelper.startPage(menuPageListRequest.getCurrentPage(), menuPageListRequest.getPageSize());
        //查询条件

        List<SysMenu> sysMenuList = sysMenuDao.list(menuPageListRequest);
        List<SysMenuDto> sysMenuDtoList = new ArrayList<>();
        for (SysMenu sysMenu : sysMenuList) {
            SysMenuDto sysMenuDto = new SysMenuDto();
            BeanUtils.copyProperties(sysMenu, sysMenuDto);
            sysMenuDtoList.add(sysMenuDto);
        }
        CommPager<SysMenuDto> pageList = new CommPager<>(page, sysMenuDtoList);
        JsonResult<CommPager<SysMenuDto>> jsonResult = new JsonResult<CommPager<SysMenuDto>>();
        jsonResult.setMsg(HttpStatusEnum.OK.getMessage()).setCode(HttpStatusEnum.OK.getCode()).setData(pageList);
        return jsonResult;
    }

    /**
     * 查询左边树列表，过滤掉button
     *
     * @return JsonResult<List < SysMenuDto>>
     */
    public JsonResult<List<SysMenuDto>> allRejectButtonList(AllRejectButtonListRequest allRejectButtonListRequest) {
        List<SysMenu> sysMenuList = sysMenuDao.allRejectButtonList(allRejectButtonListRequest);
        List<SysMenuDto> sysMenuDtoList = new ArrayList<>();
        for (SysMenu sysMenu : sysMenuList) {
            SysMenuDto sysMenuDto = new SysMenuDto();
            BeanUtils.copyProperties(sysMenu, sysMenuDto);
            sysMenuDtoList.add(sysMenuDto);
        }
        JsonResult<List<SysMenuDto>> jsonResult = new JsonResult<>();
        jsonResult.setMsg(HttpStatusEnum.OK.getMessage()).setCode(HttpStatusEnum.OK.getCode()).setData(sysMenuDtoList);
        return jsonResult;
    }

    /**
     * 插入一个菜单节点，判断code是否存在，设置菜单的LEVEL，设置父节点为非叶子节点
     *
     * @param sysMenuRequest
     * @return JsonResult
     */
    @Transactional(rollbackFor = Exception.class)
    public JsonResult<SysMenuDto> insert(SysMenuRequest sysMenuRequest) {
        JsonResult jsonResult = new JsonResult();
        //如果菜单客户类型有值,且菜单type=4,需要校验客户类型是否已经存在
        String customerType = sysMenuRequest.getCustomerType();
        if (!StringUtils.isEmpty(customerType) && Constants.MENU_TYPE_CUSTOMER_TYPE.equals(sysMenuRequest.getType())) {
            SysMenu sysMenuCustomerType = new SysMenu();
            sysMenuCustomerType.setCustomerType(customerType);
            sysMenuCustomerType.setDelFlag(Constants.DEL_FLAG_NO);
            sysMenuCustomerType.setType(Constants.MENU_TYPE_CUSTOMER_TYPE);
            int count = sysMenuDao.selectCount(sysMenuCustomerType);
            //类型已经存在直接返回
            if (count > 0) {
                jsonResult.setMsg(HttpStatusEnum.CUSTOMER_TYPE_EXIST.getMessage()).setCode(HttpStatusEnum.CUSTOMER_TYPE_EXIST.getCode());
                return jsonResult;
            }
        }

        //如果菜单SN有值,需要校验SN是否已经存在
        String sn = sysMenuRequest.getSn();
        if (!StringUtils.isEmpty(sn)) {
            SysMenu sysMenuSN = new SysMenu();
            sysMenuSN.setSn(sn);
            sysMenuSN.setDelFlag(Constants.DEL_FLAG_NO);
            int count = sysMenuDao.selectCount(sysMenuSN);
            //类型已经存在直接返回
            if (count > 0) {
                jsonResult.setMsg(HttpStatusEnum.MENU_SN_EXIST.getMessage()).setCode(HttpStatusEnum.MENU_SN_EXIST.getCode());
                return jsonResult;
            }
        }


        SysMenu sysMenu = new SysMenu();
        BeanUtils.copyProperties(sysMenuRequest, sysMenu);
        //调用方法生成code
        sysMenu.setCode(sysCodeGeneratorService.getCode(Constants.CODE_GENERATOR_MENU));
        sysMenu.setId(iPKeyGenerator.getGenerateKey());
//        sysMenu.setParentGroupId(sysMenuDao.getParentGroupById(sysMenuRequest.getId()));
        sysMenu.setUpdateDateStr(DateUtil.updateDateStr());
        sysMenu.setCreateBy(UserUtil.getCreateByName());
        sysMenu.setUpdateBy(UserUtil.getUpdateByName());
        sysMenu.setCreateByNo(UserUtil.getCreateByNo());
        sysMenu.setUpdateByNo(UserUtil.getUpdateByNo());
        int count = sysMenuDao.insertSelective(sysMenu);

        SysMenu sysMenuUpdate = new SysMenu();
        sysMenuUpdate.setId(sysMenu.getId());
        sysMenuUpdate.setParentGroupId(sysMenuDao.getParentGroupById(sysMenu.getId()));
        sysMenuDao.updateByPrimaryKeySelective(sysMenuUpdate);
        if (count > 0) {
            SysMenu sysMenuTemp = sysMenuDao.selectByPrimaryKey(sysMenu.getId());
            SysMenuDto sysMenuDtoTemp = new SysMenuDto();
            BeanUtils.copyProperties(sysMenuTemp, sysMenuDtoTemp);
            jsonResult.setData(sysMenuDtoTemp);
            jsonResult.setMsg(HttpStatusEnum.OK.getMessage()).setCode(HttpStatusEnum.OK.getCode());
        } else {
            throw new BaseException(HttpStatusEnum.FAIL.getCode(),HttpStatusEnum.FAIL.getMessage());
        }
        return jsonResult;
    }

    /**
     * 更新菜单节点
     *
     * @param sysMenuRequest
     * @return JsonResult
     */
    public JsonResult update(SysMenuRequest sysMenuRequest) {
        JsonResult jsonResult = new JsonResult();
        //如果菜单客户类型有值,且菜单type=4,需要校验客户类型的值是否已经存在
        String customerType = sysMenuRequest.getCustomerType();
        if (!StringUtils.isEmpty(customerType) && Constants.MENU_TYPE_CUSTOMER_TYPE.equals(sysMenuRequest.getType())) {
            SysMenu sysMenuCustomerType = new SysMenu();
            sysMenuCustomerType.setCustomerType(customerType);
            sysMenuCustomerType.setDelFlag(Constants.DEL_FLAG_NO);
            sysMenuCustomerType.setType(Constants.MENU_TYPE_CUSTOMER_TYPE);
            SysMenu sysMenuExit = sysMenuDao.selectOne(sysMenuCustomerType);
            //查看菜单中是否已经存在这种客户类型
            //存在的情况下需要与更新菜单做比对，如果查看到的菜单==当前更新菜单，可以更新
            if (sysMenuExit != null && !sysMenuRequest.getId().equals(sysMenuExit.getId())) {
                jsonResult.setMsg(HttpStatusEnum.CUSTOMER_TYPE_EXIST.getMessage()).setCode(HttpStatusEnum.CUSTOMER_TYPE_EXIST.getCode());
                return jsonResult;
            }
        }

        //如果菜单SN有值,需要校验SN是否已经存在
        String sn = sysMenuRequest.getSn();
        if (!StringUtils.isEmpty(sn)) {
            SysMenu sysMenuSN = new SysMenu();
            sysMenuSN.setSn(sn);
            sysMenuSN.setDelFlag(Constants.DEL_FLAG_NO);
            SysMenu sysMenuExit = sysMenuDao.selectOne(sysMenuSN);
            //类型已经存在直接返回
            if (sysMenuExit != null && !sysMenuRequest.getSn().equals(sysMenuExit.getSn())) {
                jsonResult.setMsg(HttpStatusEnum.MENU_SN_EXIST.getMessage()).setCode(HttpStatusEnum.MENU_SN_EXIST.getCode());
                return jsonResult;
            }
        }

        SysMenu sysMenu = new SysMenu();
        BeanUtils.copyProperties(sysMenuRequest, sysMenu);
//        sysMenu.setParentGroupId(sysMenuDao.getParentGroupById(sysMenuRequest.getId()));
        sysMenu.setUpdateDateStr(DateUtil.updateDateStr());
        sysMenu.setUpdateBy(UserUtil.getUpdateByName());
        sysMenu.setUpdateByNo(UserUtil.getUpdateByNo());
        int count = sysMenuDao.updateByPrimaryKeySelective(sysMenu);


        SysMenu sysMenuUpdate = new SysMenu();
        sysMenuUpdate.setId(sysMenuRequest.getId());
        sysMenuUpdate.setParentGroupId(sysMenuDao.getParentGroupById(sysMenuRequest.getId()));
        sysMenuDao.updateByPrimaryKeySelective(sysMenuUpdate);

        if (count > 0) {
            jsonResult.setMsg(HttpStatusEnum.OK.getMessage()).setCode(HttpStatusEnum.OK.getCode());
        } else {
            throw new BaseException(HttpStatusEnum.FAIL.getCode(),HttpStatusEnum.FAIL.getMessage());
        }
        return jsonResult;
    }

    /**
     * 软删除一个菜单节点
     *
     * @param sysMenuDatchDeleteRequest
     * @return JsonResult
     */
    @Transactional(rollbackFor = Exception.class)
    public JsonResult batchDelete(SysMenuDatchDeleteRequest sysMenuDatchDeleteRequest) {
        JsonResult jsonResult = new JsonResult();
        //只能删除叶子节点
        //获取节点
        if (!CollectionUtils.isEmpty(sysMenuDatchDeleteRequest.getIds())) {
            for (String strs : sysMenuDatchDeleteRequest.getIds()) {
                SysMenu sysMenu = sysMenuDao.selectByPrimaryKey(strs);
                //查看节点是否有子节点
                SysMenu sysMenuSubParam = new SysMenu();
                sysMenuSubParam.setParentId(strs);
                sysMenuSubParam.setDelFlag(Constants.DEL_FLAG_NO);
                int countSub = sysMenuDao.selectCount(sysMenuSubParam);
                if (countSub > 0) {
                    return jsonResult.setCode(HttpStatusEnum.TREE_LEAF_FLAG_YES.getCode()).setMsg(sysMenu.getNameCn() + HttpStatusEnum.TREE_LEAF_FLAG_YES.getMessage());
                }
            }
        }
        sysMenuDatchDeleteRequest.setUpdateDateStr(DateUtil.updateDateStr());
        sysMenuDatchDeleteRequest.setUpdateBy(UserUtil.getUpdateByName());
        sysMenuDatchDeleteRequest.setUpdateByNo(UserUtil.getUpdateByNo());
        int count = sysMenuDao.batchDelete(sysMenuDatchDeleteRequest);
        if (count > 0) {
            jsonResult.setMsg(HttpStatusEnum.OK.getMessage()).setCode(HttpStatusEnum.OK.getCode());
        } else {
            throw new BaseException(HttpStatusEnum.FAIL.getCode(),HttpStatusEnum.FAIL.getMessage());
        }
        return jsonResult;
    }

    /**
     * 获取菜单详情
     *
     * @param id
     * @return
     */
    public JsonResult<SysMenuDto> get(String id) {
        JsonResult<SysMenuDto> jsonResult = new JsonResult();
        SysMenu sysMenu = sysMenuDao.selectByPrimaryKey(id);
        if (sysMenu == null) {
            return jsonResult.setCode(HttpStatusEnum.RECORD_NOT_EXIST.getCode()).setMsg(HttpStatusEnum.RECORD_NOT_EXIST.getMessage());
        }
        SysMenuDto sysMenuDto = new SysMenuDto();
        BeanUtils.copyProperties(sysMenu, sysMenuDto);
        return jsonResult.setMsg(HttpStatusEnum.OK.getMessage()).setCode(HttpStatusEnum.OK.getCode()).setData(sysMenuDto);
    }

    /**
     * 启用禁用
     *
     * @param id
     * @param enableFlag
     * @return
     */
    public JsonResult updateEnableFlag(String id, String enableFlag) {
        SysMenu sysMenu = new SysMenu();
        sysMenu.setId(id);
        sysMenu.setEnableFlag(enableFlag);
        sysMenu.setUpdateDateStr(DateUtil.updateDateStr());
        sysMenu.setUpdateBy(UserUtil.getUpdateByName());
        sysMenu.setUpdateByNo(UserUtil.getUpdateByNo());
        int count = sysMenuDao.updateByPrimaryKeySelective(sysMenu);
        JsonResult jsonResult = new JsonResult();
        if (count > 0) {
            jsonResult.setMsg(HttpStatusEnum.OK.getMessage()).setCode(HttpStatusEnum.OK.getCode());
        } else {
            throw new BaseException(HttpStatusEnum.FAIL.getCode(),HttpStatusEnum.FAIL.getMessage());
        }
        return jsonResult;
    }

    /**
     * 获取客户类型下的菜单
     *
     * @param sysMenuListByCustomerTypeRequest
     * @return
     */
    public JsonResult<List<SysMenuDto>> listByCustomerType(SysMenuListByCustomerTypeRequest sysMenuListByCustomerTypeRequest) {
        JsonResult<List<SysMenuDto>> jsonResult = new JsonResult<>();
        // 获取菜单详情，用客户类型字段+type判断,可以保证只能查询出一条记录，增加菜单界面有校验
        SysMenu sysMenuCustomerType = new SysMenu();
        sysMenuCustomerType.setCustomerType(sysMenuListByCustomerTypeRequest.getCustomerType());
        sysMenuCustomerType.setType(Constants.MENU_TYPE_CUSTOMER_TYPE);
        sysMenuCustomerType.setDelFlag(Constants.DEL_FLAG_NO);
        SysMenu sysMenuInfo = sysMenuDao.selectOne(sysMenuCustomerType);
        List<SysMenuDto> sysMenuDtoList = new ArrayList<>();
        if (sysMenuInfo != null) {
            //获取菜单下的子菜单
            SysMenu sysMenuParam = new SysMenu();
            sysMenuParam.setParentId(sysMenuInfo.getId());
            List<SysMenu> sysMenuList = sysMenuDao.selectSort(sysMenuParam);
            for (SysMenu sysMenu : sysMenuList) {
                SysMenuDto sysMenuDto = new SysMenuDto();
                BeanUtils.copyProperties(sysMenu, sysMenuDto);
                sysMenuDtoList.add(sysMenuDto);
            }
        }
        jsonResult.setMsg(HttpStatusEnum.OK.getMessage()).setCode(HttpStatusEnum.OK.getCode());
        jsonResult.setData(sysMenuDtoList);
        return jsonResult;
    }

    /**
     * 获取菜单
     *
     * @param sysMenuListByIdsRequest
     * @return
     */
    public JsonResult<List<SysMenuDto>> listByIds(SysMenuListByIdsRequest sysMenuListByIdsRequest) {
        List<SysMenu> sysMenuList = sysMenuDao.listByIds(sysMenuListByIdsRequest.getIds());
        List<SysMenuDto> sysMenuDtoList = new ArrayList<>();
        for (SysMenu sysMenu : sysMenuList) {
            SysMenuDto sysMenuDto = new SysMenuDto();
            BeanUtils.copyProperties(sysMenu, sysMenuDto);
            sysMenuDtoList.add(sysMenuDto);
        }
        JsonResult<List<SysMenuDto>> jsonResult = new JsonResult<>();
        jsonResult.setMsg(HttpStatusEnum.OK.getMessage()).setCode(HttpStatusEnum.OK.getCode()).setData(sysMenuDtoList);
        return jsonResult;
    }


    public JsonResult<List<SysMenuDto>> getSubMenuList(SubMenuRequest subMenuRequest) {
        SysMenu sysMenuOne  = sysMenuDao.selectByPrimaryKey(subMenuRequest.getId());
        List<SysMenu> sysMenuList = new ArrayList<>();
        if("padmin".equals(UserUtil.getEmployeeNo())){
            sysMenuList = sysMenuDao.getSubMenuListAdmin(sysMenuOne.getParentGroupId(),subMenuRequest.getPlatform());
        }else{
            String employeeId = UserUtil.getEmployeeId();
            sysMenuList = sysMenuDao.getSubMenuList(employeeId,sysMenuOne.getParentGroupId(),subMenuRequest.getPlatform());
        }

        List<SysMenuDto> sysMenuDtoList = new ArrayList<>();
        for (SysMenu sysMenu : sysMenuList) {
            SysMenuDto sysMenuDto = new SysMenuDto();
            BeanUtils.copyProperties(sysMenu, sysMenuDto);
            sysMenuDtoList.add(sysMenuDto);
        }
        JsonResult<List<SysMenuDto>> jsonResult = new JsonResult<>();
        jsonResult.setMsg(HttpStatusEnum.OK.getMessage()).setCode(HttpStatusEnum.OK.getCode()).setData(sysMenuDtoList);
        return jsonResult;
    }

    public JsonResult updateParentGroup() {
        List<SysMenu> sysMenuList = sysMenuDao.selectAll();
        for (SysMenu sysMenu : sysMenuList) {
            String parentGroup = sysMenuDao.getParentGroupById(sysMenu.getId());
            SysMenu sysMenuParam = new SysMenu();
            sysMenuParam.setId(sysMenu.getId());
            sysMenuParam.setParentGroupId(parentGroup);
            sysMenuDao.updateByPrimaryKeySelective(sysMenuParam);
        }
        return new JsonResult<>();
    }

    public JsonResult<List<SysMenuDto>> getSubMenuListByUrl(SubMenuByUrlRequest subMenuByUrlRequest) {
        List<SysMenuDto> sysMenuDtoList = new ArrayList<>();
        SysMenu sysMenuParam = new SysMenu();
        sysMenuParam.setUrl(subMenuByUrlRequest.getUrl());
        SysMenu sysMenuOne  = sysMenuDao.selectOne(sysMenuParam);
        if(sysMenuOne != null){
            List<SysMenu> sysMenuList = new ArrayList<>();
            if("padmin".equals(UserUtil.getEmployeeNo())){
                sysMenuList = sysMenuDao.getSubMenuListAdmin(sysMenuOne.getParentGroupId(),subMenuByUrlRequest.getPlatform());
            }else{
                String employeeId = UserUtil.getEmployeeId();
                sysMenuList = sysMenuDao.getSubMenuList(employeeId,sysMenuOne.getParentGroupId(),subMenuByUrlRequest.getPlatform());
            }

            for (SysMenu sysMenu : sysMenuList) {
                SysMenuDto sysMenuDto = new SysMenuDto();
                BeanUtils.copyProperties(sysMenu, sysMenuDto);
                sysMenuDtoList.add(sysMenuDto);
            }
        }
        JsonResult<List<SysMenuDto>> jsonResult = new JsonResult<>();
        jsonResult.setMsg(HttpStatusEnum.OK.getMessage()).setCode(HttpStatusEnum.OK.getCode()).setData(sysMenuDtoList);
        return jsonResult;
    }

    public JsonResult<List<SysMenuDto>> findList(MenuListRequest menuListRequest) {
        SysMenu sysMenuParam = new SysMenu();
        sysMenuParam.setPlatform(menuListRequest.getPlatform());
        sysMenuParam.setParentId(menuListRequest.getId());
        List<SysMenu> sysMenuList = sysMenuDao.select(sysMenuParam);
        List<SysMenuDto> sysMenuDtoList = new ArrayList<>();
        for (SysMenu sysMenu : sysMenuList) {
            SysMenuDto sysMenuDto = new SysMenuDto();
            BeanUtils.copyProperties(sysMenu, sysMenuDto);
            sysMenuDtoList.add(sysMenuDto);
        }
        JsonResult<List<SysMenuDto>> jsonResult = new JsonResult<List<SysMenuDto>>();
        jsonResult.setMsg(HttpStatusEnum.OK.getMessage()).setCode(HttpStatusEnum.OK.getCode()).setData(sysMenuDtoList);
        return jsonResult;
    }

    /**
     * 更新code
     * code 规则拼接当前节点的所有上级SN
     * @return
     */
    public JsonResult updateCode() {
        List<SysMenu> sysMenuList = sysMenuDao.selectAll();
        for (SysMenu sysMenu : sysMenuList) {
            String parentSn = sysMenuDao.getParentSNById(sysMenu.getId());
            SysMenu sysMenuParam = new SysMenu();
            sysMenuParam.setId(sysMenu.getId());
            sysMenuParam.setCode(parentSn);
            sysMenuDao.updateByPrimaryKeySelective(sysMenuParam);
        }
        return new JsonResult<>();
    }

    /**
     * 获取渠道属性下所有的菜单节点
     * @param channelAttributeSubListRequest
     * @return
     */
    public JsonResult<List<SysMenuDto>> channelAttributeSubList(ChannelAttributeSubListRequest channelAttributeSubListRequest) {
        //获取渠道属性对应的菜单
        SysMenu sysMenuCustomerType = new SysMenu();
        sysMenuCustomerType.setCustomerType(channelAttributeSubListRequest.getChannelAttribute());
        sysMenuCustomerType.setType(Constants.MENU_TYPE_CUSTOMER_TYPE);
        sysMenuCustomerType.setDelFlag(Constants.DEL_FLAG_NO);
        SysMenu sysMenuInfo = sysMenuDao.selectOne(sysMenuCustomerType);
        if(sysMenuInfo == null){
            return new JsonResult<>();
        }
        //获取菜单的所有子节点
        List<SysMenu> sysMenuList = new ArrayList<>();
        String employeeId = UserUtil.getEmployeeId();
        sysMenuList = sysMenuDao.getSubMenuList(employeeId,sysMenuInfo.getParentGroupId(),channelAttributeSubListRequest.getPlatform());

        List<SysMenuDto> sysMenuDtoList = new ArrayList<>();
        for (SysMenu sysMenu : sysMenuList) {
            SysMenuDto sysMenuDto = new SysMenuDto();
            BeanUtils.copyProperties(sysMenu, sysMenuDto);
            sysMenuDtoList.add(sysMenuDto);
        }
        JsonResult<List<SysMenuDto>> jsonResult = new JsonResult<>();
        jsonResult.setMsg(HttpStatusEnum.OK.getMessage()).setCode(HttpStatusEnum.OK.getCode()).setData(sysMenuDtoList);
        return jsonResult;
    }

    public JsonResult<List<SysMenuDto>> getSNSubMenuList(SNSubMenuRequest sNsubMenuRequest) {
        List<SysMenu> sysMenuList = new ArrayList<>();

        String sn = sNsubMenuRequest.getSn();
        SysMenu sysMenuParam = new SysMenu();
        sysMenuParam.setSn(sn);
        sysMenuParam.setDelFlag("0");
        sysMenuParam.setEnableFlag("1");
        List<SysMenu> sysMenuSnList  = sysMenuDao.select(sysMenuParam);
        if(CollectionUtils.isEmpty(sysMenuSnList)){
            return new JsonResult<>();
        }
        SysMenu sysMenuOne  = sysMenuSnList.get(0);

        if("padmin".equals(UserUtil.getEmployeeNo())){
            if("CUSTOMER_LIST".equals(sn)){
                sysMenuList = sysMenuDao.getSubMenuListAdminSN(sysMenuOne.getId(),sNsubMenuRequest.getPlatform());
            }else{
                sysMenuList = sysMenuDao.getSubMenuListAdmin(sysMenuOne.getParentGroupId(),sNsubMenuRequest.getPlatform());
            }
        }else{
            String employeeId = UserUtil.getEmployeeId();
            if("CUSTOMER_LIST".equals(sn)){
                sysMenuList = sysMenuDao.getSubMenuListSN(employeeId,sysMenuOne.getId(),sNsubMenuRequest.getPlatform());
            }else {
                sysMenuList = sysMenuDao.getSubMenuList(employeeId,sysMenuOne.getParentGroupId(),sNsubMenuRequest.getPlatform());
            }
        }

        List<SysMenuDto> sysMenuDtoList = new ArrayList<>();
        for (SysMenu sysMenu : sysMenuList) {
            SysMenuDto sysMenuDto = new SysMenuDto();
            BeanUtils.copyProperties(sysMenu, sysMenuDto);
            sysMenuDtoList.add(sysMenuDto);
        }
        JsonResult<List<SysMenuDto>> jsonResult = new JsonResult<>();
        jsonResult.setMsg(HttpStatusEnum.OK.getMessage()).setCode(HttpStatusEnum.OK.getCode()).setData(sysMenuDtoList);
        return jsonResult;
    }
}
